<?php
/*******************************************************************************
 * Project: Bridge for WordPress mu to phpBB 3.0.x
 * File:    override.php
 * Author:  Jason Sanborn <jsanborn@simplicitypoint.com>
 * Date:    Saturday, July 11, 2009
 * -----------------------------------------------------------------------------
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

function wp_validate_auth_cookie($cookie = '', $scheme = '')
{
	if(!$cookie_elements = wp_parse_auth_cookie($cookie, $scheme))
	{
        echo _e("Malformed.", 'wp_phpbb_bridge');
        break;
		do_action('auth_cookie_malformed', $cookie, $scheme);
		return false;
	}

	extract($cookie_elements, EXTR_OVERWRITE);

	$expired = $expiration;
    
	// Allow a grace period for POST and AJAX requests
	if(defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'])
	{
		$expired += 3600;
	}

	// Quick check to see if an honest cookie has expired
	if($expired < time())
	{
        echo _e("Expired.", 'wp_phpbb_bridge');
        break;
		do_action('auth_cookie_expired', $cookie_elements);
		return false;
	}

	$user = get_userdatabylogin($username);
	if(!$user)
	{
        echo _e("Bad Usernaame.", 'wp_phpbb_bridge');
        break;
		do_action('auth_cookie_bad_username', $cookie_elements);
		return false;
	}

	do_action('auth_cookie_valid', $cookie_elements, $user);

	return $user->ID;
}

?>